package cn.itcast.bos.service.base.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.base.StandardService;
import cn.itcast.bos.web.Dao.base.StandardRepository;

@Service
@Transactional
public class StandardServiceImpl implements StandardService {

	/// Dao 的 注入
	@Autowired
	private StandardRepository standardRepository;

	@Override
	@CacheEvict(value = "standard", allEntries = true)
	public void save(Standard standard) {
		standardRepository.save(standard);
	}

	@Override
	@Cacheable(value = "standard", key = "#pageable.PageNumber+'_'+#pageable.PageSize")
	public Page<Standard> findDataService(Pageable pageable) {
		/// 调用Dao层进行数据库数据额查询 因为你 Dao层 继了JpaRepository 所以不需要写注解 语句 ， 可以通过调用注入的方法
		/// 进行对数据库的操作
		return standardRepository.findAll(pageable);
	}

	// 获取分派标准
	@Override
	@Cacheable("standard")
	public List<Standard> findAll() {
		return standardRepository.findAll();
	}

	/*
	 * @Override public Page<Standard>
	 * findPageService(org.springframework.data.domain.Pageable pageable) {
	 * return standardRepository.findAll(pageable); }
	 */

}
